<template>
	<view class="live">
		<view class="live-plate-1">
			<u-swiper :list="list" height="412" name="img"></u-swiper>
		</view>
		<view class="live-plate-2">
			<view class="item"  v-for="(item,index) in liveData" :key="index" @click.stop="goLiveRoom(item.live_program_id,item.live_status,item.shielding)">
				<view class="item-top">
					<view class="left">
						<image src="../../static/ic_live_be_about.png" mode="widthFix"></image>
						<text v-if="item.live_status == 1">即将直播</text>
						<text v-if="item.live_status == 2">直播中</text>
						<text v-if="item.live_status == 3">暂停中</text>
						<text v-if="item.live_status == 4">回放中</text>
					</view>
					<view class="right">
						观看人数{{item.views_number}}人
					</view>
				</view>
				<view class="item-btm">
					<view class="top"  @click.stop="onLike(index,item)">
						<u-icon name="thumb-up-fill" :color="activeIndex == index?'#D1AA56':'#fff'" size="38"></u-icon>
						<text>{{item.like_num}}</text>
					</view>
					<view class="btm">
						<u-icon name="chat" color="#fff" size="38"></u-icon>
						<text>{{item.comment_num}}</text>
					</view>
				</view>
				<view class="bottom-bg">
					<image :src="item.live_head_pic"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import IM from '@/static/js/IM.js'
	export default {
		data() {
			return {
				list:[],
				liveData:[],
				activeIndex:Number
			}
		},
		created() {
			this.getBanner()
			this.getLiveList()
		},
		onShow() {
			IM.onTab()
		},
		methods: {
			//跳转到直播间
			goLiveRoom(id, num, lahei) {
				if (lahei == 1) {
					if (num == 2) {
						uni.navigateTo({
							url: 'liveRoom?id=' + id
						})
					} else {
						uni.showToast({
							title: '直播还未开始哦~',
							icon: 'none',
							duration: 1200
						})
					}
				} else {
					uni.showToast({
						title: '已被主播拉黑',
						icon: 'none',
						duration: 1200
					})
				}
			},
			//请求banner
			getBanner(){
				uni.request({
				    url:this.$Url +'/index.php/app/Banner/bannerList',
				    method:'POST',
				    data:{
						banner_type:6
				    },
					header:{
						"token":uni.getStorageSync('token')
					},
				    success: (res) => {
				       this.list = res.data.data
				    }
				})
			},
			//请求直播列表
			getLiveList(){
				uni.request({
				    url:this.$Url +'/index.php/app/live/liveList',
				    method:'POST',
				    data:{
				       p:1,
					   list_type:1,
					   huifang_type:2
				    },
				    header:{
				        "token":uni.getStorageSync('token')
				    },
				    success: (res) => {
						if (res.data.status == 200) {
							this.liveData = res.data.data.live_program_list
						} else{
							uni.showToast({
								title:res.data.msg,
								icon:'none',
								duration:1200
							})
						}
				    }
				})
			},
			//点赞
			onLike(index,item){
				uni.request({
				    url:this.$Url +'/index.php/App/Live/changeLikeNum',
				    method:'POST',
				    data:{
						live_program_id:item.live_program_id
				    },
					header:{
						"token":uni.getStorageSync('token')
					},
				    success: (res) => {
						this.activeIndex = index
						return item.like_num++
				    }
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.live {
		.live-plate-2 {
			display: flex;
			align-items: center;
			flex-wrap: wrap;
			.item{
				width: 355rpx;
				height: 418rpx;
				border-radius: 30rpx;
				background-size: 100% 100%;
				position: relative;
				padding: 1rpx;
				margin: 10rpx;
				.bottom-bg{
					position: absolute;
					top: 0rpx;
					bottom: 0rpx;
					width: 355rpx;
					height: 418rpx;
					border-radius: 30rpx;
					z-index: -1;
					image{
						width: 355rpx;
						height: 418rpx;
						border-radius: 30rpx;
					}
				}
				.item-top{
					display: flex;
					align-items: center;
					margin: 20rpx 0 0 20rpx;
					.left{
						box-sizing: border-box;
						width: 150rpx;
						height: 50rpx;
						border-top-left-radius: 40rpx;
						border-bottom-left-radius: 40rpx;
						display: flex;
						align-items: center;
						justify-content: center;
						background-color: $zhuti-color;
						image{
							width: 32rpx;
							height: 32rpx;
						}
						text{
							font-size: 22rpx;
							margin-left: 8rpx;
							color: #fff;
						}
					}
					.right{
						box-sizing: border-box;
						width: 150rpx;
						height: 50rpx;
						border-top-right-radius: 40rpx;
						border-bottom-right-radius: 40rpx;
						background-color: rgba(255,255,255,0.2);
						display: flex;
						align-items: center;
						justify-content: center;
						font-size: 22rpx;
						color: #fff;
					}
				}
				.item-btm{
					display: flex;
					flex-direction: column;
					justify-content: flex-end;
					align-items: flex-end;
					padding-right: 20rpx;
					margin-top: 95rpx;
					.top{
						display: flex;
						align-items: center;
						justify-content: center;
						flex-direction: column;
						margin-bottom: 20rpx;
						text{
							font-size: 22rpx;
							color: #fff;
						}
					}
					.btm{
						display: flex;
						align-items: center;
						justify-content: center;
						flex-direction: column;
						text{
							font-size: 22rpx;
							color: #fff;
						}
					}
				}
			}
		}
	}
</style>
